<?php
class Edit_employee extends Model 
{
	function get_info($employee_id)
	{
		$this->db->from('employees');	
		$this->db->join('people', 'people.person_id = employees.person_id');
		$this->db->where('employees.person_id',$employee_id);
		$query = $this->db->get();
		
		if($query->num_rows()==1)
		{
			return $query->row();
		}
		else
		{
	
		}
	}
	
	
	/*
	updates an employee
	*/
	function save_update(&$person_data, &$employee_data,&$permission_data,$employee_id=false)
	{
		$success=false;
		
		//Run these queries as a transaction, we want to make sure we do all or nothing
		$this->db->trans_start();
			
		if($this->save($person_data,$employee_id))
		{
			$this->db->where('person_id', $employee_id);
			$success = $this->db->update('employees',$employee_data);		
		}
		
		$this->db->trans_complete();		
		return $success;
	}
	
	/*
	updates a person
	*/
	function save(&$person_data,$person_id=false)
	{				
		$this->db->where('person_id', $person_id);
		return $this->db->update('people',$person_data);
	}
	
	
	function get_logged_in_employee_info()
	{
		if($this->is_logged_in())
		{
			return $this->get_info($this->session->userdata('person_id'));
		}
		
		return false;
	}
	
	/*
	Determins if a employee is logged in
	*/
	function is_logged_in()
	{
		return $this->session->userdata('person_id')!=false;
	}
}

?>